<@layout.skeleton>

<@app.jsLink 'jquery.validate.js'/>
<@app.jsLink 'additional-methods.js'/>
<@app.jsLink 'validation-commons.js'/>
<@app.jsLink 'project.js'/>

<h2>
    <#if edit??>
        Edit project <a href="<@spring.url '/${currentProject.shortName}'/>">${currentProject.name}</a>
    <#else>
        New project
    </#if>
</h2>
    <form id="form" class="form-horizontal">
        <div class="control-group">
            <label for="base-url" class="control-label">Base URL</label>
            <div class="controls">
                <div class="input-append">
                    <input id="base-url" name="baseUrl" path="vcsAttributes.url" type="text" class="input-block-level" placeholder="SVN folder with trunk and branches entries" maxlength="500"
                        <#if edit??>
                           value="${currentProject.vcsAttributes.url}"
                        </#if>
                            />
                    <button id="test-url-button" type="button" class="btn">Test</button>
                </div>
                <img id="indicator" src="<@app.imgUrl 'ajax-loader.gif'/>" class="input-append hide">
                <label for="base-url" class="help-inline"></label>
            </div>
        </div>

        <div class="input-group control-group">
            <div class="control-group">
                <label for="name" class="control-label">Name</label>
                <div class="controls">
                    <input id="name" name="name" path="name" type="text" class="input-block-level" placeholder="Project's name" maxlength="64"
                        <#if edit??>
                            value="${currentProject.name}" initial-value="${currentProject.name}"
                        </#if>
                            />
                    <label for="name" class="help-inline"></label>
                </div>
            </div>
            <div class="control-group">
                <label for="short-name" class="control-label">Short name</label>
                <div class="controls">
                    <input id="short-name" name="shortName" path="shortName" type="text" class="input-block-level" placeholder="Project's short name to be used in URLs" maxlength="32"
                        <#if edit??>
                           value="${currentProject.shortName}"
                           initial-value="${currentProject.shortName}"
                        </#if>
                            />
                    <label for="short-name" class="help-inline"></label>
                </div>
            </div>
        </div>

        <div class="input-group control-group">
            <div class="control-group">
                <label for="auth-type" class="control-label">SVN authentication</label>
                <div class="form-inline controls">
                    <select id="auth-type" name="authType">
                        <#list authTypes as authType>
                            <option value="${authType}"
                                <#if edit?? && currentProject.vcsAttributes.authType == authType>
                                    selected="selected"
                                </#if>
                                    >${authType?lower_case}</option>
                        </#list>
                    </select>
                </div>
            </div>
            <div id="credentials" class="control-group">
                <div class="controls">
                    <input id="username" name="username" type="text" class="input-block-level" placeholder="Username" maxlength="255"
                        <#if edit?? && currentProject.vcsAttributes.authType == 'custom' && currentProject.vcsAttributes.username??>
                           value="${currentProject.vcsAttributes.username}"
                        </#if>
                            />
                    <input id="password" name="password" type="password" class="input-block-level" placeholder="Password" maxlength="255"
                        <#if edit?? && currentProject.vcsAttributes.authType == 'custom' && currentProject.vcsAttributes.password??>
                           value="${currentProject.vcsAttributes.password}"
                        </#if>
                            />
                </div>
            </div>
        </div>
        <div class="controls">
            <button type="submit" class="btn btn-primary">
                <#if edit??>
                    Apply
                <#else>
                    Create
                </#if>
            </button>
            <#if edit??>
                <a class="btn" href="<@spring.url '/${currentProject.shortName}?edit'/>">Reset</a>
            </#if>
        </div>
        <#if edit??>
            <input id="project-short-name" name="projectShortName" type="hidden" value="${currentProject.shortName}"/>
        </#if>
    </form>

    <#if !edit??>
        <#-- modal -->
        <div id="ask-user-modal" class="modal hide" data-backdrop="static">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h3>New project was successfully created!</h3>
            </div>
            <div class="modal-body">
                <p>Do you want to add some tasks?</p>
            </div>
            <div class="modal-footer">
                <button id="add-task-button" class="btn btn-primary" data-dismiss="modal">Yes</button>
                <button id="modal-dismiss-button" class="btn">No</button>
            </div>
        </div>
        <#-- modal end -->
    </#if>

</@layout.skeleton>
